package com.hontech.bvapp2.ui.view

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.widget.FrameLayout
import android.widget.TextView
import com.hontech.bvapp2.R


class LabelState(context: Context, attrs: AttributeSet) : FrameLayout(context, attrs) {

    private val view: View
    private val tvKey: TextView

    init {
        val view = LayoutInflater.from(context).inflate(R.layout.view_label_state, this)
        val attr = context.obtainStyledAttributes(attrs, R.styleable.LabelState)
        val key = attr.getString(R.styleable.LabelState_ls_key)
        attr.recycle()

        val tv = view.findViewById<TextView>(R.id.id_state_tv_key)
        tv.text = key

        tvKey = tv

        this.view = view.findViewById(R.id.id_state_view)
    }

    fun setKey(name: String) {
        tvKey.text = name
    }

    fun set(value: Boolean) {
        if (value) {
            view.setBackgroundResource(R.drawable.point_red)
        } else {
            view.setBackgroundResource(R.drawable.point_gray)
        }
    }
}
